<?php

class VideosModel extends Videos{

	public function insertVideos($arr){
		try {
			$obj = new Videos();
			foreach($arr as $chave => $valor){
				if($chave != 'files'){
					$chave = ucfirst($chave);
					$met = 'set'.$chave;
					$obj->$met($valor);
				}
			}
			$db = new Db;
			$db->Insert('videos',$obj);
			$this->lista = $db->res;
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function updateVideos($arr){
		try {
			$obj = new Videos();
			foreach($arr as $chave => $valor){
				if($chave != 'files'){
					$chave = ucfirst($chave);
					$met = 'set'.$chave;
					$valor = "'".$valor."'";
					$obj->$met($valor);
				}
			}			
			$db = new Db;
			$db->Update('videos',$obj);
			$this->lista = $db->res;
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function deleteVideos($id){
		try {
			$db = new Db;
			$db->Delete('videos',$id);
			$this->lista = $db->res;
		} catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function consultarVideos($parametros){
		try {
			$campos = array('*');
			$where = 'idvideos = '.$parametros;
			$order = '';
			$db = new Db;
			$db->Select('videos',$campos,$where,$order);
			$this->lista = $db->res[0];
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function listarVideos($parametros){
		try {
			$campos = array('*');
			$where = '';
			$order = 'idvideos DESC';
			$db = new Db;
			$db->Select('videos',$campos,$where,$order);
			$view = new VideosView();
			$this->lista = $view->listar($db->res);
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function visualizarVideos($parametros){
		try {
			$campos = array('*');
			$where  = '';
			$order  = 'idvideos DESC LIMIT 1';
			$db = new Db;
			$db->Select('videos',$campos,$where,$order);
			$this->lista = $db->res[0];
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
}
?>